#include "HashCode.h"
#include <math.h>
#include <random>
#include <iostream>
#include <string>
#include <sstream>
#include <io.h>
#include "sha1.h"
#include <assert.h>


using namespace std;

 //ASSERTS
     #define DEBUG
     #include <iostream>
     #ifndef DEBUG
        #define ASSERT(TextLength)
     #else
        #define ASSERT(TextLength) \
                 if (! (TextLength)) \
                { \
                   cout << "ERROR!! Assert!! Textlaenge ueberpruefen " << #TextLength << " zu gering\n"; \
                   cout << "in Zeile " << __LINE__  << "\n"; \
				   cout << "in Datei " << __FILE__ << "\n";  \
				    \
                }
    #endif

CHashCode::CHashCode(void)
{
}


CHashCode::~CHashCode(void)
{
	delete this;
}



void CHashCode::GetHashValue(const char* Text, int TextLength)
{
	ASSERT(TextLength>0);
	unsigned char hash[20];
	char hexstring[41];
	sha1::calc(Text, TextLength, hash);
	sha1::toHexString(hash,hexstring);
	/*unsigned long hash = 0;
      int i;
    
	  for (i=0; i<TextLength; i++) 
      {
		  hash = 5*hash + Text[i];
      }
    
      return hash;*/
	cout << endl << "Der SHA1 Hash lautet: ";

	for (int i=0; i<=40; i++)
	{
		cout << hexstring[i];
	}
}

